package com.htandroid.htandroid.webservice;

import android.util.Xml;

import com.htandroid.htandroid.entity.UffjqgdList_detail;
import com.htandroid.htandroid.entity.Vendor;

import org.json.JSONObject;
import org.xmlpull.v1.XmlPullParser;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

public class abXMLVendorlist {

    /**
     * 解析评论xml信息
     *
     * @param content
     * @return
     */
    public static ArrayList<Vendor> paraseCommentInfors(String content) {
        List<String> list = new ArrayList<String>();
        content = content.replace("Vendor=anyType", "#=#");
        String[] strs = content.split("#=");
        for (int i = 0; i < strs.length; i++) {
            if (strs[i].contains("#")) {
                list.add(strs[i].replace("#", "").trim().replace(" ", ""));
            }
        }
        ArrayList<Vendor> vendorList = new ArrayList<Vendor>();
        for (int i = 0; i < list.size(); i++) {
            if (i == list.size() - 1) {
                list.set(i, list.get(i).replace(";};};}", "\"}"));
            }
            list.set(i, list.get(i).replace(";};", "\"}").replace("=", "\":\"").replace(";", "\",\"").replace("{bvenTax", "{\"bvenTax"));
            try {
                Vendor info = new Vendor();
                JSONObject dataJson = new JSONObject(list.get(i));
                info.setCvenCode(string2null(dataJson.getString("cvenCode")));
                info.setCvenName(string2null(dataJson.getString("cvenName")));
                info.setCvenAbbName(string2null(dataJson.getString("cvenAbbName")));
                info.setCvccode(string2null(dataJson.getString("cvccode")));
                info.setCvcname(string2null(dataJson.getString("cvcname")));
                info.setCdccode(string2null(dataJson.getString("cdccode")));
                info.setCtrade(string2null(dataJson.getString("ctrade")));
                info.setCvenAddress(string2null(dataJson.getString("cvenAddress")));
                info.setCvenPostCode(string2null(dataJson.getString("cvenPostCode")));
                info.setCvenRegCode(string2null(dataJson.getString("cvenRegCode")));
                info.setCvenBank(string2null(dataJson.getString("cvenBank")));
                info.setCvenAccount(string2null(dataJson.getString("cvenAccount")));
                info.setDvenDevDate(string2null(dataJson.getString("dvenDevDate")));
                info.setCvenLperson(string2null(dataJson.getString("cvenLperson")));
                info.setCvenPhone(string2null(dataJson.getString("cvenPhone")));
                info.setCvenFax(string2null(dataJson.getString("cvenFax")));
                info.setCvenEmail(string2null(dataJson.getString("cvenEmail")));
                info.setCvenPerson(string2null(dataJson.getString("cvenPerson")));
                info.setCvenBp(string2null(dataJson.getString("cvenBp")));
                info.setCvenHand(string2null(dataJson.getString("cvenHand")));
                info.setCvenPperson(string2null(dataJson.getString("cvenPperson")));
                info.setIvenDisRate(string2null(dataJson.getString("ivenDisRate")));
                info.setIvenCreGrade(string2null(dataJson.getString("ivenCreGrade")));
                info.setIvenCreLine(string2null(dataJson.getString("ivenCreLine")));
                info.setIvenCreDate(string2null(dataJson.getString("ivenCreDate")));
                info.setCvenPayCond(string2null(dataJson.getString("cvenPayCond")));
                info.setCvenIaddress(string2null(dataJson.getString("cvenIaddress")));
                info.setCvenItype(string2null(dataJson.getString("cvenItype")));
                info.setCvenHeadCode(string2null(dataJson.getString("cvenHeadCode")));
                info.setCvenWhCode(string2null(dataJson.getString("cvenWhCode")));
                info.setCvenDepart(string2null(dataJson.getString("cvenDepart")));
                info.setIapmoney(string2null(dataJson.getString("iapmoney")));
                info.setDlastDate(string2null(dataJson.getString("dlastDate")));
                info.setIlastMoney(string2null(dataJson.getString("ilastMoney")));
                info.setDlrdate(string2null(dataJson.getString("dlrdate")));
                info.setIlrmoney(string2null(dataJson.getString("ilrmoney")));
                info.setDendDate(string2null(dataJson.getString("dendDate")));
                info.setIfrequency(string2null(dataJson.getString("ifrequency")));
                info.setBvenTax(string2null(dataJson.getString("bvenTax")));
                info.setCvenDefine1(string2null(dataJson.getString("cvenDefine1")));
                info.setCvenDefine2(string2null(dataJson.getString("cvenDefine2")));
                info.setCvenDefine3(string2null(dataJson.getString("cvenDefine3")));
                info.setXximport(string2null(dataJson.getString("xximport")));
                info.setDamount(string2null(dataJson.getString("damount")));
                info.setWebuser(string2null(dataJson.getString("webuser")));
                info.setWebpsw(string2null(dataJson.getString("webpsw")));
                info.setId(string2null(dataJson.getString("id")));
                vendorList.add(info);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return vendorList;
    }

    //函数作用是把null 转为空
    public static String string2null(String str) {
        String rtn = "";
        if (str == null || str.equals("null") || str.equals("anyType{}")) {
            rtn = "";
        } else {
            rtn = str;
        }
        return rtn;
    }
}
